//
//  SettingCommonCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/7/28.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit
import SDWebImage

class SettingCommonCell: BaseTableViewCell {
    
    @IBOutlet weak var imgView: UIImageView!
    
    @IBOutlet weak var label: UILabel!
    
    var dic : [String : String]?{
        
        didSet{
            
            imgView.image = UIImage(named: dic!["imageName"]!)
            
            if dic?["title"] == "清除缓存"{
                
                label.text = "清除缓存(\(fileSizeWithInterge()))"

            }else{
                
                label.text = dic?["title"]

            
            }
            
            
        }
        
        
    }
    
    
    func fileSizeWithInterge() -> String {
        
        let temp = SDImageCache.shared().getSize()
        
        if (temp < 1024) {// 小于1k
            return "\(temp)B"
        }else if (temp < 1024 * 1024){// 小于1m
            let aFloat : Float = Float(temp)/1024;
            return String(format: "%.2fKB", arguments: [aFloat])
        }else if (temp < 1024 * 1024 * 1024){// 小于1G
            let aFloat : Float = Float(temp)/(1024 * 1024)
            
            return String(format: "%.2fMB", arguments: [aFloat]) //"\(aFloat)MB"
        }else{
            let aFloat : Float = Float(temp)/(1024 * 1024 * 1024)
            return String(format: "%.2fGB", arguments: [aFloat]) //"\(aFloat)GB"
        }
        
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        contentView.backgroundColor = UIColor.white
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
